Skip to content

[Minor] Add speech models#232

Merged
aryamanarora merged 2 commits into
stanfordnlp:mainfrom
taka-yamakoshi:taka/speech
Jan 29, 2026
Merged

[Minor] Add speech models#232
aryamanarora merged 2 commits into
stanfordnlp:mainfrom
taka-yamakoshi:taka/speech

Conversation

@taka-yamakoshi
Copy link
Copy Markdown

Description

Added speech models (Whisper & Wav2Vec-BERT).
Allow batched multi-token interventions.

Testing Done

Passed unit tests.

Checklist:

  • My PR title strictly follows the format: [Your Priority] Your Title
  • I have attached the testing log above
  • I provide enough comments to my code
  • I have changed documentations
  • I have added tests for my changes

Taka Yamakoshi and others added 2 commits January 28, 2026 15:37
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 30616d7889

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

whisper_type_to_module_mapping = {
"block_input": ("encoder.layers[%s]", CONST_INPUT_HOOK),
"block_output": ("encoder.layers[%s]", CONST_OUTPUT_HOOK),
"mlp_activation": ("encoder.layers[%s].activation_fn", CONST_OUTPUT_HOOK),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid hooking Whisper activation_fn callable

In HuggingFace Whisper, encoder.layers[*].activation_fn is a plain callable from ACT2FN, not an nn.Module. get_module_hook later calls register_forward_hook on the resolved object (see pyvene/models/modeling_utils.py:get_module_hook), so registering mlp_activation will raise an AttributeError at runtime whenever a user selects that intervention. Consider hooking a real module (e.g., fc1 output) or wrapping the activation in an nn.Module before registering.

Useful? React with 👍 / 👎.

Comment on lines +15 to +18
"ffn1_activation": ("encoder.layers[%s].ffn1.intermediate_act_fn", CONST_OUTPUT_HOOK),
"ffn1_output": ("encoder.layers[%s].ffn1", CONST_OUTPUT_HOOK),
"ffn1_input": ("encoder.layers[%s].ffn1", CONST_INPUT_HOOK),
"ffn2_activation": ("encoder.layers[%s].ffn2.intermediate_act_fn", CONST_OUTPUT_HOOK),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not map Wav2Vec2Bert ffn activations to intermediate_act_fn

ffn1.intermediate_act_fn and ffn2.intermediate_act_fn are callables rather than nn.Modules in the HF implementation, so get_module_hook (which calls register_forward_hook) will fail when users request ffn*_activation interventions. This makes those intervention points unusable and will raise at hook registration time.

Useful? React with 👍 / 👎.

@aryamanarora
Copy link
Copy Markdown
Member

@taka-yamakoshi I think codex is wrong since we hook onto act_fn elsewhere too with no problems. I'm going to merge, but do double check that that works just in case I am wrong!

@aryamanarora aryamanarora self-assigned this Jan 29, 2026
Copy link
Copy Markdown
Member

@aryamanarora aryamanarora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@aryamanarora aryamanarora merged commit 96b4d43 into stanfordnlp:main Jan 29, 2026
1 of 2 checks passed
@taka-yamakoshi
Copy link
Copy Markdown
Author

I checked it just now, and it seems to work just fine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants